package com.itxh.core.handler.statement;

import com.itxh.core.config.BoundSql;
import com.itxh.core.config.MappedStatement;

import java.sql.Connection;
import java.sql.Statement;
import java.util.List;

public class RoutingStatementHandler implements StatementHandler{
    private StatementHandler delegate;

    public RoutingStatementHandler(String statementType) {
        switch (statementType) {
            case "prepared" :
                delegate = new PreparedStatementHandler();
                break;
            case "statement" :
                delegate = new SimpleStatementHandler();
                break;
            case "callable" :
                delegate = new CallableStatementHandler();
                break;
            default :
                delegate = new PreparedStatementHandler();
                break;
        }
    }

    @Override
    public Statement prepare(Connection connection, String sql)  throws Exception{
        return delegate.prepare(connection,sql);
    }

    @Override
    public void parameterize(Statement statement, Object param, BoundSql boundSql)  throws Exception{
        delegate.parameterize(statement, param, boundSql);
    }

    @Override
    public <T> List<T> query(Statement statement, BoundSql boundSql, MappedStatement mappedStatement)  throws Exception{
        return delegate.query(statement, boundSql, mappedStatement);
    }
}
